import request from '@/api/request'
import { reactive } from 'vue'

class EchartsStore {
  constructor() {
    this.view = reactive({
      data: {},
      status: 0
    })
  }

  async getDate(config) {
    let url = this.url || config.url
    try {
      this.view.status = 1
      const result = await request.get(url)

      if (result && result.status === 200) {
        this.view.status = 2
        this.view.data = this.changeData(result)
      }
    } catch (error) {
      this.view.status = 3
      // 在用trycatch 但是没有准确的错误处理方式 需要添加
    }
  }
  // 数据序列化
  changeData(res) {
    return res.data.data[0]
  }
}

export default EchartsStore
